* This file creates Figure D2
* Note: You must run AppD_make_D2_data.do first to create necessary datasets

set more off


*********************************
** MAKE APPENDIX D FIGURE D2
*********************************

use "$saveddata/assumption_150180.dta", clear
gen group=2
append using "$saveddata/assumption_180210.dta"
replace group=3 if group2==.
append using "$saveddata/assumption_210240.dta"
replace group=4 if group2==.
append using "$saveddata/assumption_0150.dta"
replace group=1 if group2==.

gen lower = beta-1.96*se
gen upper = beta+1.96*se

label define group 1 "<150" 2 "150-180" 3 "180-210" 4 "210-240"
label values group group

* Group 1
twoway scatter beta coeff if coeff!=0 & group==1 & coeff<370,msymbol(O) connect(line) lcolor(black) mcolor(black) msize(small) || scatter lower coeff if coeff!=0 & group==1 & coeff<370, msymbol(none) msize(small) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) || ///
scatter upper coeff if coeff!=0 & group==1 & coeff<370, msymbol(none) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) msize(small) ///
xtitle("") ytitle("Standardised beta coefficient") legend(off) graphregion(color(white))  xtick(0(40)360) xlab(0(40)360,nolab) xline(240, lpattern(dash) lcolor(black)) ytick(0(1)4) ylab(0(1)4) subtitle("(a) <150 minutes") saving(group1, replace) 

* Group 2
twoway scatter beta coeff if coeff!=0 & group==2 & coeff<370,msymbol(O) msize(small) connect(line) lcolor(black) mcolor(black) || scatter lower coeff if coeff!=0 & group==2 & coeff<370, msymbol(none) msize(small) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) || ///
scatter upper coeff if coeff!=0 & group==2 & coeff<370, msymbol(none) msize(small) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) ///
xtitle("") ytitle("") legend(off) graphregion(color(white))  xtick(0(40)360) xlab(0(40)360,nolab) xline(240, lpattern(dash) lcolor(black)) ytick(0(1)4) ylab(0(1)4,nolab) subtitle("(b) 150-180 minutes") saving(group2, replace) 

* Group 3
twoway scatter beta coeff if coeff!=0 & group==3 & coeff<370,msymbol(O) msize(small) connect(line) lcolor(black) mcolor(black) || scatter lower coeff if coeff!=0 & group==3 & coeff<370, msymbol(none) msize(small) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) || ///
scatter upper coeff if coeff!=0 & group==3 & coeff<370, msymbol(none) msize(small) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) ///
xtitle("Wait time in queue (mins)") ytitle("Standardised beta coefficient") legend(off) graphregion(color(white))  xtick(0(40)360) xlab(0(40)360) xline(240, lpattern(dash) lcolor(black)) ytick(0(1)4) ylab(0(1)4) subtitle("(c) 180-210 minutes") saving(group3, replace)

* Group 4
twoway scatter beta coeff if coeff!=0 & group==4 & coeff<370,msymbol(O) msize(small) connect(line) lcolor(black) mcolor(black) || scatter lower coeff if coeff!=0 & group==4 & coeff<370, msymbol(none) msize(small) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) || ///
scatter upper coeff if coeff!=0 & group==4 & coeff<370, msymbol(none) msize(small) connect(line) lpattern(shortdash) lcolor(black) mcolor(black) ///
xtitle("Wait time in queue (mins)") ytitle("") legend(off) graphregion(color(white))  xtick(0(40)360) xlab(0(40)360) xline(240, lpattern(dash) lcolor(black)) ytick(0(1)4)  ylabel(0(1)4,nolabels) subtitle("(d) 210-240 minutes") saving(group4, replace)

graph combine group1.gph group2.gph group3.gph group4.gph, graphregion(color(white)) 
graph export "$results/FigD2.pdf", as(pdf) replace 
